<?php

namespace App\Http\Middleware;

use App\Project\Reserve\Exceptions\ReservationForbiddenException;
use Closure;
use Silber\Bouncer\Bouncer;

class ReservationAuthAndAuthCache
{
    /**
     * Handle an incoming request.
     * @param          $request
     * @param \Closure $next
     * @return mixed
     * @throws \App\Project\Reserve\Exceptions\ReservationForbiddenException
     */
    public function handle($request, Closure $next)
    {
        app(Bouncer::class)->cache();

        if (\Auth::user()->canReservation()) {
            return $next($request);
        }

        abort(403, '暂无操作预约系统的权限！');
    }
}
